package oh.june.kwon.util;

import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.TransitionContext;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngineInstance;

public class TransitionManager {
	public static final int MODE_SCREEN = 0 ; 
	public static final int MODE_MODAL_SCREEN = 1;

	public static void pushZoomScreen(Screen screen){
		pushZoomScreen(screen, MODE_SCREEN); 
	}
	public static void pushZoomScreen(Screen screen, int mode){
		TransitionContext transitionContextIn;
		TransitionContext transitionContextOut;
		UiEngineInstance engine = Ui.getUiEngineInstance();

		transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_FADE);
		transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 500);                    

		transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_FADE);
		transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 500); 
		transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT); 

		engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
		engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);

		if(mode == MODE_SCREEN)
			UiApplication.getUiApplication().pushScreen(screen);
		else if(mode == MODE_MODAL_SCREEN)
			UiApplication.getUiApplication().pushModalScreen(screen);
	}
	
	public static void pushSlidingScreen(Screen screen){
		TransitionContext transition = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
		transition.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
		transition.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_RIGHT);
		transition.setIntAttribute(TransitionContext.ATTR_STYLE, TransitionContext.STYLE_PUSH);

		UiEngineInstance engine = Ui.getUiEngineInstance();
		engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transition);

		transition = new TransitionContext(TransitionContext.TRANSITION_FADE);
		transition.setIntAttribute(TransitionContext.ATTR_DURATION, 500);
		transition.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);
		engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transition); 
		
		UiApplication.getUiApplication().pushScreen(screen);
	}

}
